package company.jingji;

import java.util.Scanner;
import java.util.Stack;

/**
 * 判断嵌套是否匹配
 *
 * @author briarbear
 * @blog https://briarbear.github.io
 * @date 2018-09-20 15:02
 */
public class J3 {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        boolean res;

        String _str;
        try {
            _str = in.nextLine();
        } catch (Exception e) {
            _str = null;
        }

        res = isMatch(_str);
        System.out.println(String.valueOf(res ? 1 : 0));
    }

    private static boolean isMatch(String str) {
        if (str == null || str.equals("")) return true;
        Stack<Character> stack = new Stack<>();
        for (int i = 0; i < str.length(); i++) {
            switch (str.charAt(i)){
                case ')':if (!stack.isEmpty() && stack.peek() == '('){
                    stack.pop();break;
                }else return false;
                case ']':if (!stack.isEmpty() && stack.peek() == '['){
                    stack.pop();break;
                }else return false;
                case '}':if (!stack.isEmpty() && stack.peek() == '{'){
                    stack.pop();break;
                }else return false;
                default:stack.push(str.charAt(i));
            }
        }

        return stack.isEmpty();
    }
}
